//
//  MODingCanViewCell.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/10/17.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MODingCanViewCell.h"

@interface MODingCanViewCell ()

@property(nonatomic,assign)CGFloat cellWidth;

@property(nonatomic,strong)UILabel *nameLabel;

@property(nonatomic,strong)UILabel *monthPayNumberLabel;

@property(nonatomic,strong)UILabel *priceLabel;

@property(nonatomic,strong)UIButton *reduceButton;

@property(nonatomic,strong)UILabel *numberLabel;

@property(nonatomic,strong)UIButton *addButton;

@end

@implementation MODingCanViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath cellWidth:(CGFloat)cellWidth;
{
    //NSString *ID = [NSString stringWithFormat:@"Cell%ld%ld",(long)[indexPath section],(long)[indexPath row]];
    NSString *ID = @"MODingCanViewCell";
    MODingCanViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil){
        cell = [[MODingCanViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell creatViewCellWidth:cellWidth];
    }
    return cell;
}


-(void)creatViewCellWidth:(CGFloat)cellWidth
{
    self.cellWidth = cellWidth;
    
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(18, 16, cellWidth-36, 15)];
    self.nameLabel.font = FONT_SIZE(16);
    self.nameLabel.textColor = KBlackColor_2A2A2A;
    [self addSubview:self.nameLabel];
    
    self.monthPayNumberLabel = [[UILabel alloc]initWithFrame:CGRectMake(18, 16, cellWidth-36, 15)];
    self.monthPayNumberLabel.font = FONT_SIZE(13);
    self.monthPayNumberLabel.textColor = KBlackColor_2A2A2A;
    self.monthPayNumberLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.monthPayNumberLabel];
    
    self.priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(18, self.nameLabel.bottom + 19, 60, 13)];
    self.priceLabel.font = FONT_SIZE(13);
    self.priceLabel.textColor = KBlackColor_2A2A2A;
    [self addSubview:self.priceLabel];
    
    self.reduceButton = [[UIButton alloc]initWithFrame:CGRectMake(cellWidth-104, 0, 19, 19)];
    self.reduceButton.centerY =self.priceLabel.centerY;
    self.reduceButton.layer.masksToBounds = YES;
    self.reduceButton.layer.cornerRadius = 9.5;
    [self.reduceButton setBackgroundColor:KBlueColor_2C94FF];
    [self.reduceButton setContentVerticalAlignment:(UIControlContentVerticalAlignmentCenter)];
    self.reduceButton.titleLabel.font = FONT_SIZE(15);
    [self.reduceButton addTarget:self action:@selector(clickReduceButton) forControlEvents:UIControlEventTouchUpInside];
    [self.reduceButton setImage:IMAGE(@"dingcan_reduce") forState:UIControlStateNormal];
    [self addSubview:self.reduceButton];
    
    self.numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.reduceButton.right, 0, 50, 20)];
    self.numberLabel.centerY =self.priceLabel.centerY;
    self.numberLabel.font = FONT_SIZE(13);
    self.numberLabel.textColor = KBlackColor_2A2A2A;
    self.numberLabel.textAlignment = NSTextAlignmentCenter;
    self.numberLabel.text = @"0";
    [self addSubview:self.numberLabel];
    
    self.addButton = [[UIButton alloc]initWithFrame:CGRectMake(cellWidth-35, 0, 19, 19)];
    self.addButton.centerY =self.priceLabel.centerY;
    self.addButton.layer.masksToBounds = YES;
    self.addButton.layer.cornerRadius = 9.5;
    [self.addButton setBackgroundColor:KBlueColor_2C94FF];
    self.addButton.titleLabel.font = FONT_SIZE(15);
    [self.addButton setImage:IMAGE(@"dingcan_add") forState:UIControlStateNormal];
    [self.addButton addTarget:self action:@selector(clickAddButton) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.addButton];
}

-(void)clickReduceButton{
    if (self.clickReduceBlock) {
        self.clickReduceBlock();
    }
}

-(void)clickAddButton
{
    if (self.clickAddBlock) {
        self.clickAddBlock();
    }
}

-(void)setModel:(MODingCanModel *)model
{
    self.nameLabel.text = model.nameStr;
    self.monthPayNumberLabel.text = [NSString stringWithFormat:@"月销：%@",model.monthPayNumber];
    self.priceLabel.text = [NSString stringWithFormat:@"单价：%@",model.priceStr];
    self.numberLabel.text = model.numberStr;
}

@end
